package api

import (
	"github.com/gogf/gf/net/ghttp"
	"github.com/gogf/gf/util/gconv"
	"github.com/google/uuid"
	"github.com/zhang201702/zhang"
	"usad2/app/service"
)

type PptApi struct {
	BaseApi
}

func init() {
	registerApi("ppt", func(name string) Api {
		return &PptApi{BaseApi: *NewBaseApi(name, name)}
	})
}
func (api *PptApi) Register(s *zhang.ServerGF) {
	//api.BaseApi = *NewApi("ppt", "ppt")
	api.BaseApi.Register(s)
	s.BindHandler("/ppt/upload", api.picUpload)
	s.BindHandler("/ppt/copy", func(r *ghttp.Request) {
		service2 := api.service.(*service.PptService)
		var data = api.GetJsonMap(r)
		id := gconv.String(data["id"])
		if id == "" {
			api.ErrorResult("copy,非法参数", nil, r)
			return
		}
		result, err := service2.Copy(id)
		api.Result(result, err, r)
	})
}

func (api *PptApi) picUpload(r *ghttp.Request) {
	_, path := uploadFile(r, "/img/ppt/")
	if path != "" {
		/// name := r.GetString("name")
		//cert := g.Map{"name": name, "path": path}
		//_, err := api.service.Insert(font)
		path = path + "?" + uuid.New().String()
		api.Result(path, nil, r)
	}
}
